using System;
using System.Collections.Generic;
using Oracle.ManagedDataAccess.Client;

namespace OracleInternal.Sharding
{
	internal class RangeShardingKeys : ShardingKeys
	{
		private List<Tuple<OracleShardingKeyImpl, OracleShardingKeyImpl>> m_keys;

		internal OracleShardingKeyImpl KeyHigh
		{
			get;
			set;
		}

		internal OracleShardingKeyImpl KeyLow
		{
			get;
			set;
		}

		internal override List<Tuple<OracleShardingKeyImpl, OracleShardingKeyImpl>> Keys
		{
			get
			{
				return m_keys;
			}
			set
			{
				m_keys = value;
			}
		}

		internal RangeShardingKeys(OracleShardingKeyImpl keyHigh, OracleShardingKeyImpl keyLow)
		{
			KeyHigh = keyHigh;
			KeyLow = keyLow;
			m_keys = new List<Tuple<OracleShardingKeyImpl, OracleShardingKeyImpl>>(1);
			m_keys.Add(new Tuple<OracleShardingKeyImpl, OracleShardingKeyImpl>(keyLow, keyHigh));
		}

		public override int GetHashCode()
		{
			return 31 * KeyLow.GetHashCode() + KeyHigh.GetHashCode();
		}

		public override bool Equals(object obj)
		{
			RangeShardingKeys rangeShardingKeys = obj as RangeShardingKeys;
			if (rangeShardingKeys == null)
			{
				return false;
			}
			if (KeyLow == null || KeyHigh == null)
			{
				throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.SHARDING_INVALID_TOPOLOGY));
			}
			if (KeyLow.Equals(rangeShardingKeys.KeyLow) && KeyHigh.Equals(rangeShardingKeys.KeyHigh))
			{
				return true;
			}
			return false;
		}
	}
}
